#include <cmath>

#include "Tile.h"

using namespace std;  // Because the sqrt() function really belongs here.

namespace fullsail_ai {

	Tile::Tile(int r, int c, double radius, unsigned char data)
		: weight(data), row(r), column(c)
		, x(((r & 1) ? ((c + 1) << 1) : ((c << 1) | 1)) * radius)
		, y((r * 3 + 2) * radius / sqrt(3.0))
		, marker_color(0), outline_color(0), fill_color(0), line_color(0)
		, line_destination(0)
	{
	}

	void Tile::setRadius(double radius)
	{
		x = ((row & 1) ? ((column + 1) << 1) : ((column << 1) | 1)) * radius;
		y = (row * 3 + 2) * radius / sqrt(3.0);
	}

	int Tile::convertColorModel(int color)
	{
		unsigned char first = ~(color >> 24);
		unsigned char second = color;
		unsigned char third = (color >> 8);
		unsigned char fourth = (color >> 16);

		return ((int)first << 24) | ((int)second << 16) | ((int)third << 8) | (int)fourth;
	}
}  // namespace fullsail_ai

